import request from '@/utils/request'

const api = {
  salesPersonList: '/sale/salesPersonList',
  orderList: '/sale/orderList',
  clientList: '/sale/clientList',
  auditorList: '/user/auditorList',
  add: '/sale/add',
  detail: '/sale/detail'
}

// 销售员
export function salesPersonList () {
  return request({
    method: 'get',
    url: api.salesPersonList
  })
}

const Map = {
  'descend': 'desc',
  'ascend': 'asc'
}

// 订单列表
export function orderList (parameter) {
  parameter = parameter || {} // 支持不传参数
  return request({
    method: 'get',
    url: api.orderList,
    params: {
      order: Map[parameter.order] || 'asc',
      page: parameter.page || 1,
      pageSize: parameter.pageSize || 10,
      code: parameter.code || null,
      salesPerson: parameter.salesPerson,
      status: parameter.status
    }
  })
}

// 客户列表
export function clientList () {
  return request({
    method: 'get',
    url: api.clientList
  })
}

// 审核员列表
export function auditorList () {
  return request({
    method: 'get',
    url: api.auditorList
  })
}

// 物品列表
export function stuffList () {
  return request({
    method: 'get',
    url: '/supply/list'
  })
}

// add
export function add (paramater) {
  return request({
    method: 'post',
    url: api.add,
    data: paramater
  })
}

// detail
export function detail (parameter) {
  return request({
    method: 'get',
    url: api.detail,
    params: {
      saleCode: parameter.saleCode
    }
  })
}
